const BaseIpcHandler = require('../BaseIpcHandler');

class NewMapWndHandler extends BaseIpcHandler {
    async handle(event, params) {
        // 解析参数
        // console.log('>> NewWndHandler params = ', params);
        const { lat, lng, zoom, mode } = JSON.parse(params.position);
        // lat: 39.908, lng: 116.397, zoom: 15

        // 业务逻辑
        let result = { code: 0, msg: 'New window ok!' };
        const ELECTRON_ENV = process.env.ELECTRON_ENV;
        if (ELECTRON_ENV) {
            await this.app.mapwnd.createMapsWindow({
                lat,
                lng,
                zoom,
                mode
            });
            result = { code: 0, msg: 'Open capture window ok!' };
        } else {
            result = { code: -1, msg: 'Open app without electron!' };
        }

        // 返回结果
        if (event.from === 'localserver') {
            event.resp.send(result);
        } else {
            return result;
        }
    }
}

module.exports = NewMapWndHandler;
